package boot

import (
	"fmt"
	"gitee.com/igolang/pkg/xtime"
	"os"
	"runtime"
	"time"
)

const (
	ModeHttp = "http"
)

var (
	RunMode   string
	version   string
	buildTime string

	Pid       = os.Getpid()
	StartTime = xtime.Time(time.Now())
)

func IsHttp() bool {
	return RunMode == ModeHttp
}

type info struct {
	Version   string     `json:"version"`
	BuildTime string     `json:"buildTime"`
	Pid       int        `json:"pid"`
	StartTime xtime.Time `json:"startTime"`
	GoVersion string     `json:"goVersion"`
}

func (i *info) String() string {
	return fmt.Sprintf(`buildTime: %s, version: %s, startTime: %s,pid: %v, go version: %s`,
		i.BuildTime, i.Version, i.StartTime.String(), i.Pid, runtime.Version(),
	)
}
func Info() *info {
	return &info{
		Version:   version,
		BuildTime: buildTime,
		Pid:       Pid,
		StartTime: StartTime,
		GoVersion: runtime.Version(),
	}
}
